<!DOCTYPE html>
<html lang="en">
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <style>
        /*body {background-image:url(背景2.jg);}*/
        p{
            text-align: center;
            font-size:300%;
            font-weight: bold;
        }

        .form_top{
            margin-top: 50px;
        }
    </style>
</head>
<body onload="showUser()">
<!--    <hr><hr><hr>-->
<!--    <form action="/Login_Forest/LoginServlet" method="get">-->
<!--        用户名:<input type="text" name = "username"><br>-->
<!--        密码：<input type="text" name = "password"><br>-->
<!--        <button type="submit" class="btn btn-success">登录</button>-->
<!--&lt;!&ndash;        <input type="submit" value="Submit">&ndash;&gt;-->
<!--    </form>-->
<%int username = 2;%>
<div id = "login">没有东西</div>
<input type="hidden" id="id" value="<%=username%>"/>
<input type="button" id="btn_01"   value="提交表单">
<script type="text/javascript" language="javascript">
    var id;
    function showUser(){
        id = document.getElementById("id").value;//通过那个隐藏表单就获取到了需要的值，成功传入JS代码中
    }
    var btn_01 = document.getElementById("btn_01");
    btn_01.onclick = function add_gold() {
        //发送异步请求,1创建核心对象
        var xmlhttp;
        if(window.XMLHttpRequest){
            xmlhttp = new  XMLHttpRequest();
        }
        else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        //2建立连接
        xmlhttp.open("GET","add_servlet?id="+id+"",true);
        //3发送请求
        xmlhttp.send();
        //4响应请求
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                alert("成功了");
            }
        };
    }
</script>
</body>
</html>